package com.css.fxfzypg.modules.baseData.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.baseData.entity.*;
import com.css.fxfzypg.modules.baseData.service.SeismicSetoutService;
import com.css.fxfzypg.modules.baseData.queryParams.SeismicSetoutQueryParams;
import com.css.fxfzypg.modules.baseData.vo.ScSeismicSetoutVO;
import com.css.fxfzypg.modules.baseData.vo.ScSeismicSetoutVO1;
import com.css.fxfzypg.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/fxfzypg/baseData")
@Slf4j
public class SeismicSetoutController {

    @Resource
    SeismicSetoutService seismicSetoutService ;


    /**
     * 新增seismicSetout
     * @param seismicSetout
     * @return
     */
    @PostMapping("/saveSeismicSetout1")
    public RestResponse saveSeismicSetout1 (@RequestBody ScSeismicSetoutVO1 seismicSetout){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveSeismicSetout1(seismicSetout);
        }catch (Exception e){
            log.error("新增地震应急准备情况失败",e);
            restResponse = RestResponse.fail("新增地震应急准备情况失败!");
        }
        return restResponse;
    }

    /**
     *
     * @param type
     * @param provinceId
     * @param cityId
     * @param prefectureId
     * @param file
     * @return
     */
    @PostMapping("/saveSeismicSetout2")
    public RestResponse saveSeismicSetout2 (@RequestParam("type") String type, @RequestParam("provinceId") String provinceId,
                                            @RequestParam("cityId") String cityId,@RequestParam("prefectureId") String prefectureId,
                                            MultipartFile file){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveSeismicSetout2(type,provinceId,cityId,prefectureId,file);
        }catch (Exception e){
            log.error("新增地震应急准备情况失败",e);
            restResponse = RestResponse.fail("新增地震应急准备情况失败!");
        }
        return restResponse;
    }
    /**
     * 新增seismicSetout
     * @param seismicSetout
     * @return
     */
    @PostMapping("/saveSeismicSetout")
    public RestResponse saveSeismicSetout (@RequestBody ScSeismicsetout seismicSetout){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveSeismicSetout(seismicSetout);
        }catch (Exception e){
            log.error("新增地震应急准备情况失败",e);
            restResponse = RestResponse.fail("新增地震应急准备情况失败!");
        }
        return restResponse;
    }
    /**
     * 新增ScSupplies
     * @param scSupplies
     * @return
     */
    @PostMapping("/saveScSupplies")
    public RestResponse saveScSupplies (@RequestBody ScSupplies scSupplies){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveScSupplies(scSupplies);
        }catch (Exception e){
            log.error("新增应急物资储备失败",e);
            restResponse = RestResponse.fail("新增应急物资储备失败!");
        }
        return restResponse;
    }
    /**
     * ScRescue
     * @param scRescue
     * @return
     */
    @PostMapping("/saveScRescue")
    public RestResponse saveScRescue (@RequestBody ScRescue scRescue){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveScRescue(scRescue);
        }catch (Exception e){
            log.error("新增应急救援力量失败",e);
            restResponse = RestResponse.fail("新增应急救援力量失败!");
        }
        return restResponse;
    }
    /**
     * ScRescue
     * @param scEquip
     * @return
     */
    @PostMapping("/saveScEquip")
    public RestResponse saveScEquip (@RequestBody ScEquip scEquip){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveScEquip(scEquip);
        }catch (Exception e){
            log.error("新增应急救援装备失败",e);
            restResponse = RestResponse.fail("新增应急救援装备失败!");
        }
        return restResponse;
    }
    /**
     * ScRescue
     * @param scSanctuary
     * @return
     */
    @PostMapping("/saveScSanctuary")
    public RestResponse saveScSanctuary (@RequestBody ScSanctuary scSanctuary){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveScSanctuary(scSanctuary);
        }catch (Exception e){
            log.error("新增避难场所失败",e);
            restResponse = RestResponse.fail("新增避难场所失败!");
        }
        return restResponse;
    }
    /**
     * ScRescue
     * @param scMedical
     * @return
     */
    @PostMapping("/saveScMedical")
    public RestResponse saveScMedical (@RequestBody ScMedical scMedical){
        RestResponse restResponse = null ;
        try{
            restResponse = seismicSetoutService.saveScMedical(scMedical);
        }catch (Exception e){
            log.error("新增医疗力量失败",e);
            restResponse = RestResponse.fail("新增医疗力量失败!");
        }
        return restResponse;
    }

    /**
     * 全查询  模糊查询  为条件
     * @param request
     * @param queryParams
     * @return
     */
    @GetMapping("/getAllSeismicSetout")
    public RestResponse getAllSeismicSetout(HttpServletRequest request, SeismicSetoutQueryParams queryParams){

        RestResponse restResponse = null;
        try{
           int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
           int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            // queryParams.setCurPage(Integer.parseInt(PlatformPageUtils.CUR_PAGE_DEF));
            // queryParams.setPageSize(Integer.parseInt(PlatformPageUtils.PAGE_SIZE_DEF));
            restResponse = RestResponse.succeed(seismicSetoutService.getAllSeismicSetout(queryParams,curPage,pageSize));
        }catch (Exception e){
            log.error("查询地震应急准备情况失败!",e);
            restResponse = RestResponse.fail("查询地震应急准备情况失败");
        }
        return restResponse;
    }

    /**
     * 根据id查询主表SeismicSetout数据
     * @param id 主键id:scId
     * @return
     */
    @GetMapping("/getSeismicSetout")
    public RestResponse getSeismicSetout(@RequestParam("id") String id) {
        RestResponse restResponse = null;
        try{
            restResponse = RestResponse.succeed(seismicSetoutService.getSeismicSetoutById(id));
        }catch (Exception e){
            log.error("获取地震应急准备情况数据失败!",e);
            restResponse = RestResponse.fail("获取地震应急准备情况数据失败!");
        }
        return restResponse;
    }
    /**
     * 根据id查询从表数据
     * @param id 外键id:scId
     * @return
     */
    @GetMapping("/getDetails")
    public RestResponse getDetails(HttpServletRequest request, @RequestParam("id") String id,@RequestParam("type") String type) {
        RestResponse restResponse = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse = seismicSetoutService.getDetailsById(id,type,curPage,pageSize);
        }catch (Exception e){
            log.error("获取地震应急准备情况数据失败!",e);
            restResponse = RestResponse.fail("获取地震应急准备情况数据失败!");
        }
        return restResponse;
    }
    /**
     * 据id查询从表数据
     * @param id 主键id
     * @return
     */
    @GetMapping("/getDetail")
    public RestResponse getDetail(@RequestParam("id") String id,@RequestParam("type") String type) {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.getDetailById(id,type);
        }catch (Exception e){
            log.error("获取地震应急准备情况数据失败!",e);
            restResponse = RestResponse.fail("获取地震应急准备情况数据失败!");
        }
        return restResponse;
    }

    /**
     * 逻辑删除，修改数据标志位
     * @param id
     * @return
     */
    @PostMapping("/delSeismicSetout")
    public RestResponse deleteSeismicSetout(@RequestParam("id") String id,@RequestParam("type") String type) {
        RestResponse restResponse = null;
        try{
            seismicSetoutService.deleteSeismicSetouts(id,type);
            restResponse = RestResponse.succeed();
        }catch (Exception e){
            log.error("删除地震应急准备情况失败!",e);
            restResponse = RestResponse.fail("删除地震应急准备情况失败!");
        }
        return restResponse;
    }

    /**
     * 修改
     * @param scSeismicsetout
     * @return
     */
    @PostMapping("/updateSeismicSetout")
    public RestResponse updateSeismicSetout(@RequestBody ScSeismicsetout scSeismicsetout)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateSeismicSetout(scSeismicsetout);
        }catch (Exception e){
            log.error("修改地震应急准备情况失败!",e);
            restResponse = RestResponse.fail("修改地震应急准备情况失败!");
        }
        return restResponse;
    }
    /**
     * 修改
     * @param scSupplies
     * @return
     */
    @PostMapping("/updateScSupplies")
    public RestResponse updateScSupplies(@RequestBody ScSupplies scSupplies)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateScSupplies(scSupplies);
        }catch (Exception e){
            log.error("修改应急物资储备失败!",e);
            restResponse = RestResponse.fail("修改应急物资储备失败!");
        }
        return restResponse;
    }
    /**
     * 修改
     * @param scRescue
     * @return
     */
    @PostMapping("/updateScRescue")
    public RestResponse updateScRescue(@RequestBody ScRescue scRescue)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateScRescue(scRescue);
        }catch (Exception e){
            log.error("修改应急救援力量失败!",e);
            restResponse = RestResponse.fail("修改应急救援力量失败!");
        }
        return restResponse;
    }
    /**
     * 修改
     * @param scEquip
     * @return
     */
    @PostMapping("/updateScEquip")
    public RestResponse updateScEquip(@RequestBody ScEquip scEquip)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateScEquip(scEquip);
        }catch (Exception e){
            log.error("修改应急救援装备失败!",e);
            restResponse = RestResponse.fail("修改应急救援装备失败!");
        }
        return restResponse;
    }
    /**
     * 修改
     * @param scSanctuary
     * @return
     */
    @PostMapping("/updateScSanctuary")
    public RestResponse updateScSanctuary(@RequestBody ScSanctuary scSanctuary)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateScSanctuary(scSanctuary);
        }catch (Exception e){
            log.error("修改避难场所失败!",e);
            restResponse = RestResponse.fail("修改避难场所失败!");
        }
        return restResponse;
    }
    /**
     * 修改
     * @param scMedical
     * @return
     */
    @PostMapping("/updateScMedical")
    public RestResponse updateScMedical(@RequestBody ScMedical scMedical)  {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.updateScMedical(scMedical);
        }catch (Exception e){
            log.error("修改医疗力量失败!",e);
            restResponse = RestResponse.fail("修改医疗力量失败!");
        }
        return restResponse;
    }

    /**
     * 导出表内数据
     * @param response
     * @throws IOException
     */
    @PostMapping("/exportExcelSeismicSetout")
    public void exportExcel(HttpServletResponse response ) throws IOException {
        try{
            log.error("功能暂时缺失");
            // List<SeismicSetout> list  = seismicSetoutService.getAll();
            // FileUtil.exportExcel(list, "地震应急准备情况数据", "sheet", SeismicSetout.class, "SeismicSetout", response);
        }catch (Exception e){
            log.error("导出失败",e);
        }
    }

    /**
     * 导入数据
     * @param file
     * @throws IOException
     */
    @PostMapping("/importExcel")
    public RestResponse importExcel(@RequestParam String type,@RequestParam String scId, MultipartFile file) throws IOException {
        RestResponse restResponse = null;
        try{
            restResponse = seismicSetoutService.importExcel(type,scId,file);
        }catch (Exception e){
            log.error("导入失败",e);
        }
        return restResponse ;
    }

}
